/**
 * 结束单人
 */
class FinishPersonItem extends eui.Component {

    private head: HeadIcon;
    private zan: eui.Image;
    private win: eui.Image;
    private pao: eui.Image;
    private textGroup: eui.Group;
    private lab_zhuang: eui.Label;
    private lab_hupai: eui.Label;
    private lab_zimo: eui.Label;
    private lab_dianpao: eui.Label;
    private lab_jiepao: eui.Label;
    private lab_angang: eui.Label;
    private lab_minggang: eui.Label;
    private lab_zongfen: eui.Label;
    private card_group: eui.Group;
    private img_reward_type: eui.Image;
    private lab_reward_num: eui.BitmapLabel;

    public person: any;

    constructor(p: any) {
        super();

        this.skinName = "FinishPersonItemSkin";

        this.person = p;
    }

    childrenCreated() {
        super.childrenCreated();

        this.head.skinState = "intheend";

        gameManager.i.addEventListener(GameEventType.UPDATE_ASSESS_DATA, this.onUpdate, this);
    }

    private onUpdate(data: any) {
        let appraise: any = data;
        if (appraise && appraise.hasOwnProperty(this.person.uid)) {
            this.zan.source = appraise[this.person.uid] == 1 ? "assess_ico_good_1" : "assess_ico_bad_1";
        }
    }

    refresh() {

        let data = game.roomPlayers[this.person.uid];
        this.person.cai = data.cai;
        this.person.zan = data.zan;

        this.head.update(new PlayerVo(this.person));

        this.zan.source = "assess_ico_good_1";
        this.zan.visible = this.person.uid != game.player.uid;

        this.lab_zhuang.text = "坐  庄：" + this.person.zhuang_num;
        this.lab_hupai.text = "胡  牌：" + this.person.hu_num;
        this.lab_zimo.text = "自  摸：" + this.person.zimo_num;
        this.lab_dianpao.text = "点  炮：" + this.person.pao_num;
        this.lab_jiepao.text = "接  炮：" + this.person.paorcv_num;
        this.lab_angang.text = "暗  杠：" + this.person.gang_an_num;
        this.lab_minggang.text = "明  杠：" + this.person.gang_ming_num;
        this.lab_zongfen.text = "积  分：" + this.person.cur;

        if (this.textGroup.contains(this.lab_jiepao)) {
            this.textGroup.removeChild(this.lab_jiepao);
        }
        if (this.textGroup.contains(this.lab_angang)) {
            this.textGroup.removeChild(this.lab_angang);
        }
        if (this.textGroup.contains(this.lab_minggang)) {
            this.textGroup.removeChild(this.lab_minggang);
        }

        this.win.visible = this.person["iswin"];
        this.pao.visible = this.person["ispao"];

        let new_card: number = +this.person.new_card;
        if (new_card > 0) {
            this.img_reward_type.source = +this.person.pos == 1 ? "card_jiangli2" : "card_jiangli1";
            this.lab_reward_num.text = `x${new_card}`;
        }

        this.card_group.visible = new_card > 0;
    }
}